/*
 * @file    interSection.cpp
 * @author  libo <libo@tencent.com>
 * @date    2013-03-24
 * @brief   
 * */

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

void printVector(vector<int> &v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << endl;
    }
}

vector<int> findIntersection(vector<int> &a, vector<int> &b)
{
   sort(a.begin(), a.end());
   sort(b.begin(), b.end());

   int i = 0;
   int j = 0;

   vector<int> ret;
   while(i < a.size() && j < b.size()) {
       if(a[i] == b[j]) {
            ret.push_back(a[i]);
            i++;
            j++;
       } else if(a[i] < b[j]) {
            i++;
       } else {
            j++;
       }
   }
   return ret;
}

int main() {

    int ints1[] = {1, 2, -100, 90, 100, 123, 5, 32, 43, 23, 11};
    int ints2[] = {1, 2, -100, 90, 100, 5123, 5, 32, 43, 23, 11};

    vector<int> v1(ints1, ints1 + sizeof(ints1) / sizeof(int));
    vector<int> v2(ints2, ints2 + sizeof(ints2) / sizeof(int));

    vector<int> res = findIntersection(v1, v2);
    printVector(res);
}
